package com.doyled.jump.framework;

import java.awt.CardLayout;
import java.awt.Component;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.doyled.jump.scene.GameScene;
import com.doyled.jump.scene.MenuScene;
import com.doyled.jump.util.SceneKind;

public class SceneManager {
	private JPanel window;
	private MenuScene menuScene;
	private GameScene gameScene;
	private static SceneManager sceneManager;

	public void setMenuScene(MenuScene menuScene) {
		this.menuScene = menuScene;
	}

	public void setGameScene(GameScene gameScene) {
		this.gameScene = gameScene;
	}

	public static SceneManager getInstanse() {
		return sceneManager;
	}

	public static void initSceneManager(JPanel window) {
		if (sceneManager == null) {
			sceneManager = new SceneManager(window);
		}
	}

	public SceneManager(JPanel window) {
		this.window = window;
	}
	
	public void setMenuScene(String sceneKind) {
		changeScene(sceneKind);
	}
	
	public void setGameScene(String sceneKind) {
		changeScene(sceneKind);
	}

	private void changeScene(String sceneKind) {
		switch (sceneKind) {
		case "Menu Scene":
			gameScene.stop();
			showScene(sceneKind);
			break;

		default:
			showScene(sceneKind);
			gameScene.start();
			break;
		}
	}

	private void showScene(String sceneKind) {
		CardLayout cardLayout = (CardLayout)this.window.getLayout();
		cardLayout.show(window, sceneKind);
	}

}
